Http Post测试,支持上传文件
req = HttpWebRequest.Create(sUrl) as HttpWebRequest;
req.Method = sMode;
req.Accept = "*/*";
req.KeepAlive = false;
req.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
if (0 == string.Compare("POST", sMode))
{
byte[] bufPost = myEncoding.GetBytes(sPostData);
req.ContentType = sContentType;
req.ContentLength = bufPost.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(bufPost, 0, bufPost.Length);
newStream.Close();
}
// Response
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
try
{
评论